<?php

class BenchExample implements Benchmark
{
    private
        $filename;
    
    public function __construct($filename = null)
    {
        if($filename === null)
        {
            $filename = '/this/a/dummy/path/for/testing/file.png';
        }
        
        $this->filename = $filename;
    }
    
    /**
     * @Benchcase(name='Php core function', color='red')
     */
    public function pathinfo()
    {
        return pathinfo($this->filename, PATHINFO_EXTENSION);
    }
    
    /**
     * @Benchcase(name='Regular expression', color='blue')
     */
    public function regexp()
    {
        return preg_replace('~^([^\.]*)\.~', '', $this->filename);
    }
    
    /**
     * @Benchcase(name='Preg match', color='violet')
     */
    public function regexp2()
    {
        if(preg_match('~\.(.*)$~', $this->filename, $matches))
        {
            return $matches[1];
        }
        return '';
    }
    
    /**
     * @Benchcase(name='Substring', color='orange')
     */
    public function substringMethod()
    {
        // dummy ;-)
        return substr($this->filename, -3);
    }
    
    /**
     * @Benchcase(name='SplFileInfo', color='green')
     */
    public function spl()
    {
        $info = new SplFileInfo($this->filename);
        // PHP 5.3.6
        // return $info->getExtension();
        return $info->getPathname();
    }
}